<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
  </head>
  <body>
    <button onclick="showAll()">显示全部基因</button><button onclick="showCandidates()">只显示候选基因</button>
    <script>
      function showAll() {
        document.querySelectorAll('tr').forEach(function(element, index) {
          element.style.display = 'table-row'
        })
      }

      function showCandidates() {
        document.querySelectorAll('tr').forEach(function(element, index) {
          element.style.display = 'none'
        })

        document.querySelectorAll('tr.candidate').forEach(function(element, index) {
          element.style.display = 'table-row'
        })
      }
    </script>
    <table>
      <xsl:for-each select="genes/gene">
        <xsl:variable name="url">trans/<xsl:value-of select="." />.xml</xsl:variable>
        <xsl:variable name="doc" select="document($url)" />
        <tr>
          <xsl:attribute name="style">
            background-color:
            <xsl:choose>
              <xsl:when test="contains($doc/gene/Text-Summary, 'Ubiquitous expression in')">
                grey
              </xsl:when>
              <xsl:otherwise>
                transparent
              </xsl:otherwise>
            </xsl:choose>
            ;
            text-decoration:
            <xsl:choose>
              <xsl:when test="contains($doc/gene/Text-Summary, 'expression in brain')">
                underline
              </xsl:when>
              <xsl:otherwise>
                none
              </xsl:otherwise>
            </xsl:choose>
            ;
          </xsl:attribute>
          <xsl:attribute name="class">
            <xsl:choose>
              <xsl:when test="contains($doc/gene/Text-Summary, 'expression in brain')">
                candidate
              </xsl:when>
            </xsl:choose>
          </xsl:attribute>
          <td>
            <a target="_blank">
              <xsl:attribute name="href">
                https://www.ncbi.nlm.nih.gov/gene/<xsl:value-of select="$doc/gene/@id" />
              </xsl:attribute>
              <xsl:value-of select="$doc/gene/@symbol" />
            </a>
          </td>
          <xsl:for-each select="$doc/gene/child::node()">
            <td><xsl:value-of select="." /></td>
          </xsl:for-each>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

<xsl:output
method="html"
indent="yes" />
</xsl:stylesheet>
